home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / desaware / stgtools / stg_demo / cfbrowsr.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-24  |  15.7 KB  |  423 lines

  1. VERSION 4.00
  2. Begin VB.Form BaseForm 
  3.    BorderStyle     =   0  'None
  4.    Caption         =   "Structured Storage Browser"
  5.    ClientHeight    =   3495
  6.    ClientLeft      =   1065
  7.    ClientTop       =   1680
  8.    ClientWidth     =   5775
  9.    Height          =   4185
  10.    Icon            =   "CFBROWSR.frx":0000
  11.    Left            =   1005
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   3495
  15.    ScaleWidth      =   5775
  16.    Top             =   1050
  17.    Width           =   5895
  18.    Begin VB.CommandButton Command1 
  19.       Caption         =   "View Contents"
  20.       Enabled         =   0   'False
  21.       Height          =   495
  22.       Left            =   2760
  23.       TabIndex        =   1
  24.       Top             =   2880
  25.       Width           =   2895
  26.    End
  27.    Begin DwstgLibDemo.DwStorage DwStorage1 
  28.       Left            =   2760
  29.       Top             =   2160
  30.       _Version        =   65536
  31.       _ExtentX        =   741
  32.       _ExtentY        =   741
  33.       _StockProps     =   0
  34.    End
  35.    Begin VB.Label AboutText 
  36.       BackStyle       =   0  'Transparent
  37.       Height          =   2295
  38.       Left            =   2760
  39.       TabIndex        =   4
  40.       Top             =   600
  41.       Width           =   3015
  42.    End
  43.    Begin MSOutl.Outline FilesList 
  44.       Height          =   3015
  45.       Left            =   120
  46.       TabIndex        =   0
  47.       Top             =   360
  48.       Width           =   2535
  49.       _Version        =   65536
  50.       _ExtentX        =   4471
  51.       _ExtentY        =   5318
  52.       _StockProps     =   77
  53.       MouseIcon       =   "CFBROWSR.frx":030A
  54.       Style           =   5
  55.       PicturePlus     =   "CFBROWSR.frx":0326
  56.       PictureMinus    =   "CFBROWSR.frx":0498
  57.       PictureLeaf     =   "CFBROWSR.frx":060A
  58.       PictureOpen     =   "CFBROWSR.frx":077C
  59.       PictureClosed   =   "CFBROWSR.frx":08EE
  60.    End
  61.    Begin VB.Label AboutFile 
  62.       BackStyle       =   0  'Transparent
  63.       BeginProperty Font 
  64.          name            =   "MS Sans Serif"
  65.          charset         =   0
  66.          weight          =   700
  67.          size            =   8.25
  68.          underline       =   0   'False
  69.          italic          =   0   'False
  70.          strikethrough   =   0   'False
  71.       EndProperty
  72.       Height          =   255
  73.       Left            =   2760
  74.       TabIndex        =   3
  75.       Top             =   360
  76.       Width           =   3015
  77.    End
  78.    Begin VB.Label Directory 
  79.       BackStyle       =   0  'Transparent
  80.       Height          =   255
  81.       Left            =   120
  82.       TabIndex        =   2
  83.       Top             =   120
  84.       Width           =   5655
  85.    End
  86.    Begin VB.Menu menuFile 
  87.       Caption         =   "&File"
  88.       Begin VB.Menu menuLoad 
  89.          Caption         =   "&Load Compound File..."
  90.       End
  91.       Begin VB.Menu FatAlbert 
  92.          Caption         =   "-"
  93.       End
  94.       Begin VB.Menu menuExit 
  95.          Caption         =   "&Exit"
  96.       End
  97.    End
  98.    Begin VB.Menu menuHelp 
  99.       Caption         =   "&Help"
  100.       Begin VB.Menu menuOther 
  101.          Caption         =   "&Other Desaware Products..."
  102.       End
  103.       Begin VB.Menu menuRudy 
  104.          Caption         =   "-"
  105.       End
  106.       Begin VB.Menu menuAbout 
  107.          Caption         =   "&About StorageBrowser..."
  108.       End
  109.    End
  110. Attribute VB_Name = "BaseForm"
  111. Attribute VB_Creatable = False
  112. Attribute VB_Exposed = False
  113. Option Explicit
  114. Dim ParentStorage As Object ' contains the parent of the currently open stream or storage
  115. Dim TempStorage As Object
  116. Dim TempStream As Object
  117. Dim EOL As String * 2 ' line feed and carriage return
  118. Dim RootExists As Boolean ' True if a storage is currently open
  119. Dim ReadOnly As Boolean   ' True if the currently open storage is read only
  120. ' These are for use by the File Open and Save common dialogs.
  121. Const vbOFNHideReadOnly = &H4&
  122. Const vbOFNFileMustExist = &H1000&
  123. ' This correctly shows the sub-elements of an item that
  124. ' was expanded.
  125. Private Sub DoExpand(ListIndex As Integer)
  126.     Dim i As Integer
  127.     Dim newIndent As Integer
  128.     ' Only read the elements in a storage once, in order
  129.     ' to reduce disk access and improve speed.
  130.     If (FilesList.HasSubItems(ListIndex) = False) Then
  131.         BaseForm.MousePointer = 11
  132.         newIndent = FilesList.Indent(ListIndex) + 1
  133.         ReadChildren FilesList.FullPath(ListIndex), ListIndex + 1, newIndent
  134.         BaseForm.MousePointer = 0
  135.     End If
  136.     FilesList.Expand(ListIndex) = True
  137. End Sub
  138. ' Reads the elements in a specific storage and enters
  139. ' them into the outline listbox.
  140. Public Sub ReadChildren(storage As String, ListIndex As Integer, level As Integer)
  141.     Dim i As Integer
  142.     Dim text As String
  143.     Dim FileType As Integer
  144. On Error GoTo badStorage
  145.     Set TempStorage = GlobalRootStorage.OpenStorage(storage, STG_READ Or STG_TRANSACTED Or STG_SHARE_EXCLUSIVE)
  146.     i = 0
  147.     Do
  148.         text = TempStorage.Directory(i, FileType)
  149.         If FileType = STG_TYPE_NONE Then Exit Do
  150.         FilesList.AddItem (text), (ListIndex + i)
  151.         FilesList.Indent(ListIndex + i) = level
  152.         FilesList.ItemData(ListIndex + i) = FileType
  153.         If FileType = STG_TYPE_STORAGE Then
  154.             FilesList.PictureType(ListIndex + i) = outClosed
  155.         ElseIf FileType = STG_TYPE_STREAM Then
  156.             FilesList.PictureType(ListIndex + i) = outLeaf
  157.         End If
  158.         i = i + 1
  159.     Loop
  160.     Set TempStorage = Nothing
  161.     ListIndex = ListIndex - 1
  162.     Exit Sub
  163. badStorage:
  164.     MsgBox "Error while searching storage:" & Chr$(13) & Err.Description
  165.     Exit Sub
  166. End Sub
  167. ' This brings up a window that allows the user to view the contents
  168. ' of a stream.
  169. Private Sub Command1_Click()
  170.     Dim path As String
  171.     Dim pathLength As Integer
  172.     ' Make sure something is selected.
  173.     If FilesList.ListIndex = -1 Then Exit Sub
  174.     ' Make sure the selected element is a stream.
  175.     If FilesList.ItemData(FilesList.ListIndex) = STG_TYPE_STREAM Then
  176.         ' Treat Summary Info Property Sets differently
  177.         If (FilesList.List(FilesList.ListIndex) = (Chr$(5) & "SummaryInformation")) Then
  178.             If (RootExists = False) Then Exit Sub
  179.             SIView.Show
  180.             Exit Sub
  181.         End If
  182.         ' Get the data
  183.         path = FilesList.FullPath(FilesList.ListIndex)
  184.         pathLength = Len(path) - Len(FilesList.List(FilesList.ListIndex))
  185.         If (pathLength > 0) Then
  186.             path = Left(path, pathLength - 1)
  187.             Set TempStorage = GlobalRootStorage.OpenStorage(path, STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  188.             Set TempStream = TempStorage.OpenStream(FilesList.List(FilesList.ListIndex), STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  189.         Else
  190.             Set TempStream = GlobalRootStorage.OpenStream(FilesList.List(FilesList.ListIndex), STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  191.         End If
  192.         GlobalSize = TempStream.GetSize()
  193. #If Win16 Then
  194.         If (GlobalSize > 65400) Then ' not 65536 to give it room for overhead
  195.             GlobalSize = 65400
  196.         End If
  197. #End If
  198.         GlobalText = String(GlobalSize, 0)
  199.         ' Get the information in the stream into a variable BinaryEdit can use.
  200.         TempStream.Get 0, GlobalText
  201.         BinaryEdit.Show
  202.         ' Always set the objects to nothing when you are done!
  203.         Set TempStorage = Nothing
  204.         Set TempStream = Nothing
  205.     End If
  206. End Sub
  207. ' Respond when the user clicks in the outline listbox.
  208. Private Sub FilesList_Click()
  209.     Dim name As String
  210.     Dim special As Integer
  211.     Dim FullText As String
  212.     Dim StorageDate As Date
  213.     Dim size As Long
  214.     Dim path As String
  215.     Dim pathLength As Integer
  216.     If FilesList.ListCount = 0 Then Exit Sub
  217.     ' enable the menu items that depend on an element
  218.     ' being selected
  219.     Command1.Enabled = True
  220.     AboutText.Caption = ""
  221.     ' get rid of special first char, but remember it
  222.     name = FilesList.List(FilesList.ListIndex)
  223.     If Asc(Mid(name, 1, 1)) < 32 Then
  224.         special = Asc(Mid(name, 1, 1))
  225.         name = Right$(name, Len(name) - 1)
  226.     End If
  227.     ' Put descriptive information into the labels.
  228.     AboutFile.Caption = name
  229.     FullText = "full path:" & EOL
  230.     path = FilesList.FullPath(FilesList.ListIndex)
  231.     pathLength = Len(path) - Len(FilesList.List(FilesList.ListIndex))
  232.     If pathLength = 0 Then
  233.         path = ""
  234.     Else
  235.         path = Left(path, pathLength - 1)
  236.     End If
  237.     FullText = FullText & "\" & path & EOL
  238.     Select Case special
  239.         Case 1, 2
  240.             FullText = FullText & "Reserved for use by the OLE libraries" & EOL
  241.         Case 3
  242.             FullText = FullText & "Reserved for use by the container of the OLE object which owns this file." & EOL
  243.         Case 4
  244.             FullText = FullText & "Reserved for use by the Structured Storage implementation." & EOL
  245.         Case 5
  246.             FullText = FullText & "Reserved as a publicly available description of this file." & EOL
  247.         Case 6 To 31
  248.             FullText = FullText & "Reserved by an unknown agent" & EOL
  249.         'case else is a normal element
  250.     End Select
  251.     FullText = FullText & EOL
  252.     If (FilesList.ItemData(FilesList.ListIndex) = 1) Then
  253.         FullText = FullText & "this is a Storage" & EOL
  254.         Set TempStorage = GlobalRootStorage.OpenStorage(FilesList.FullPath(FilesList.ListIndex), STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  255.         StorageDate = TempStorage.GetCreationDate()
  256.         FullText = FullText & "created : " & EOL & "   " & StorageDate & EOL
  257.         StorageDate = TempStorage.GetLastModifyDate()
  258.         FullText = FullText & "last Modified : " & EOL & "   " & StorageDate & EOL
  259.         StorageDate = TempStorage.GetLastAccessDate()
  260.         If StorageDate <> 0 Then
  261.             FullText = FullText & "last Access : " & EOL & "   " & StorageDate & EOL
  262.         End If
  263.         Set TempStorage = Nothing
  264.     Else
  265.         FullText = FullText & "this is a Stream" & EOL
  266.         If (pathLength > 0) Then
  267.             Set TempStorage = GlobalRootStorage.OpenStorage(path, STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  268.             Set TempStream = TempStorage.OpenStream(FilesList.List(FilesList.ListIndex), STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  269.         Else
  270.             Set TempStream = GlobalRootStorage.OpenStream(FilesList.List(FilesList.ListIndex), STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  271.         End If
  272.         size = TempStream.GetSize()
  273.         FullText = FullText & "size : " & size & " bytes" & EOL
  274.         Set TempStream = Nothing
  275.         Set TempStorage = Nothing
  276.     End If
  277.     AboutText.Caption = FullText
  278. End Sub
  279. Private Sub FilesList_Collapse(ListIndex As Integer)
  280.     Dim i As Integer
  281.     i = 1
  282.     If (FilesList.HasSubItems(ListIndex) = True) Then
  283.         Do While (FilesList.Indent(ListIndex + i) > FilesList.Indent(ListIndex))
  284.             If FilesList.PictureType(ListIndex + i) = outOpen Then
  285.                 FilesList.PictureType(ListIndex + i) = outClosed
  286.             End If
  287.             i = i + 1
  288.             If ((ListIndex + i) >= FilesList.ListCount) Then Exit Do
  289.         Loop
  290.     Else
  291.         If FilesList.PictureType(ListIndex + i) = outOpen Then
  292.             FilesList.PictureType(ListIndex + i) = outClosed
  293.         End If
  294.     End If
  295. End Sub
  296. ' Expand or collapse the tree.
  297. Private Sub FilesList_DblClick()
  298.     If FilesList.PictureType(FilesList.ListIndex) = outLeaf Then Exit Sub
  299.     If FilesList.Expand(FilesList.ListIndex) Then
  300.         FilesList.PictureType(FilesList.ListIndex) = outClosed
  301.         FilesList.Expand(FilesList.ListIndex) = False
  302.     Else
  303.         FilesList.PictureType(FilesList.ListIndex) = outOpen
  304.         DoExpand (FilesList.ListIndex)
  305.     End If
  306. End Sub
  307. Private Sub FilesList_PictureClick(ListIndex As Integer)
  308.     If FilesList.ListIndex = -1 Then Exit Sub
  309.     If FilesList.PictureType(FilesList.ListIndex) = outLeaf Then Exit Sub
  310.     If FilesList.Expand(FilesList.ListIndex) Then
  311.         FilesList.PictureType(FilesList.ListIndex) = outClosed
  312.         FilesList.Expand(FilesList.ListIndex) = False
  313.     Else
  314.         FilesList.PictureType(FilesList.ListIndex) = outOpen
  315.         DoExpand (FilesList.ListIndex)
  316.     End If
  317. End Sub
  318. ' Set up some global variables and values.
  319. Private Sub Form_Load()
  320.     Set GlobalRootStorage = Nothing
  321.     Set TempStream = Nothing
  322.     Set TempStorage = Nothing
  323.     RootExists = False ' I have not yet loaded a storage file.
  324.     Command1.Enabled = False
  325.     EOL = Chr$(13) & Chr$(10)
  326. End Sub
  327. ' Clear the objects, destroying the objects they used to contain.
  328. Private Sub Form_Unload(Cancel As Integer)
  329.     Set GlobalRootStorage = Nothing
  330.     Set TempStream = Nothing
  331.     Set TempStorage = Nothing
  332.     'Unload BaseForm
  333. End Sub
  334. ' Bring up the About box
  335. Private Sub menuAbout_Click()
  336.     Load About
  337.     About.Show
  338. End Sub
  339. ' Cleans up and exits the program.
  340. Private Sub menuExit_Click()
  341.     If RootExists And (ReadOnly = False) Then
  342.         GlobalRootStorage.Revert
  343.     End If
  344.     Unload BaseForm
  345.     End
  346. End Sub
  347. ' Brings up the Load File common dialog box and opens the file specified.
  348. Private Sub menuLoad_Click()
  349.     Dim file As String
  350.     Dim i As Integer
  351.     Dim text As String
  352.     Dim FileType As Integer
  353.     Dim RetVal As Integer
  354.     Set TempStream = Nothing
  355.     Set TempStorage = Nothing
  356.     file = App.path & "\test.stg"
  357.     If DwStorage1.IsStorageFile(file) = False Then
  358.         MsgBox "The test file is probably corrupt."
  359.         Exit Sub
  360.     Else
  361.         If RootExists Then GlobalRootStorage.Revert
  362.         Set GlobalRootStorage = Nothing
  363.         FilesList.Clear
  364.         On Error GoTo loadProblem2
  365.         Set GlobalRootStorage = DwStorage1.OpenStorageFile(file, STG_READWRITE Or STG_TRANSACTED Or STG_SHARE_EXCLUSIVE)
  366.         On Error GoTo 0
  367.         ReadOnly = False
  368.         RootExists = True
  369.     End If
  370.     Directory = file
  371. readDirectory: ' this reads the directory of the root storage
  372.     AboutFile.Caption = ""
  373.     AboutText.Caption = ""
  374.     i = 0
  375.     Do
  376.         text = GlobalRootStorage.Directory(i, FileType)
  377.         ' This code would delete the special character
  378.         ' if it exists, so you don't get that block in
  379.         ' front of the name.
  380.         'If Asc(Mid(text, 1, 1)) < 32 Then
  381.         '    text = Right$(text, Len(text) - 1)
  382.         'End If
  383.         If FileType = STG_TYPE_NONE Then Exit Do
  384.         FilesList.AddItem text
  385.         FilesList.ItemData(i) = FileType
  386.         If FileType = STG_TYPE_STORAGE Then
  387.             FilesList.PictureType(i) = outClosed
  388.         ElseIf FileType = STG_TYPE_STREAM Then
  389.             FilesList.PictureType(i) = outLeaf
  390.         End If
  391.         i = i + 1
  392.     Loop
  393.     If i = 0 Then MsgBox "This storage is empty."
  394. Exit Sub
  395. loadProblem1:
  396.     On Error GoTo notJustReadOnly
  397.     If Err.Number = STG_E_ACCESSDENIED Then
  398.         Set GlobalRootStorage = DwStorage1.CreateStorageFile(file, STG_CONVERT Or STG_READ Or STG_TRANSACTED Or STG_SHARE_EXCLUSIVE)
  399.         ReadOnly = True
  400.         Resume readDirectory
  401.     Else
  402.         MsgBox "Error durring load:" & Chr$(13) & Err.Description & ",," & Err.Number
  403.         RootExists = False
  404.         Exit Sub
  405.     End If
  406. loadProblem2:
  407.     If Err.Number = STG_E_ACCESSDENIED Then 'read only
  408.         On Error GoTo notJustReadOnly
  409.         Set GlobalRootStorage = DwStorage1.OpenStorageFile(file, STG_READ Or STG_DIRECT Or STG_SHARE_EXCLUSIVE)
  410.         ReadOnly = True
  411.         Resume readDirectory
  412.     Else
  413. notJustReadOnly:
  414.         MsgBox "Error durring load: " & Chr$(13) & Err.Description & "," & Err.Number
  415.         RootExists = False
  416.         Exit Sub
  417.     End If
  418. End Sub
  419. Private Sub menuOther_Click()
  420.     Load sdother
  421.     sdother.Show
  422. End Sub
  423.